/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hibernate.util;

/**
 *
 * @author ashwin
 */
/**
 *
 * @author Sebastian Hennebrueder
 * created Feb 22, 2006
 * copyright 2006 by http://www.laliluna.de
 */
//package de.laliluna.hibernate;
import twitter.TweetDetails;
import model.Location;
import model.UserData;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
/**
 * @author hennebrueder This class garanties that only one single SessionFactory
 *         is instanciated and that the configuration is done thread safe as
 *         singleton. Actually it only wraps the Hibernate SessionFactory.
 *         You are free to use any kind of JTA or Thread transactionFactories.
 */
public class SessionFactoryUtil {

  /** The single instance of hibernate SessionFactory */
  private static org.hibernate.SessionFactory sessionFactory;

	/**
	 * disable contructor to guaranty a single instance
	 */
	private SessionFactoryUtil() {
	}

	static{
// Annotation and XML
    AnnotationConfiguration cfg = new AnnotationConfiguration();
// ... set other configuration options programmatically

        //  Model mappings

// Claases used to craete table
    cfg.addAnnotatedClass(Location.class).addAnnotatedClass(UserData.class).addAnnotatedClass(TweetDetails.class);

      SchemaExport schemaExport = new SchemaExport(cfg);
    schemaExport.drop(true, true);
  schemaExport.create(true, true);


    // Creates sessionFcatory Object for database
    sessionFactory =cfg.buildSessionFactory();

  }

 public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
}
